package com.monitor.interceptor;

import com.monitor.common.MonitorConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Title: ApiOpenIdInterceptor.java 
* @Package com.order.interceptor 
* @Description: TODO(拦截器用来获取acctoken) 
* @author baizhixing   
* @date 2017年5月22日 下午1:58:59 
* @version V1.0
 */
public class LoginInterceptor implements HandlerInterceptor {

	private final Logger logger= LoggerFactory.getLogger(this.getClass());


	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		if(request.getSession().getAttribute(MonitorConstants.USER_SESSION_KEY)!=null){
			logger.info("用户验证成功");
			return true;
		}else{
			// 未登录，重定向到登录页
			logger.info("用户未登录，跳转登陆页面");
			response.sendRedirect(request.getContextPath()+"/login");
			return false;
		}
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
